//
//  XS_CouponHeaderView.swift
//  XueDao
//
//  Created by Mac on 2020/12/26.
//

import UIKit

protocol XS_CouponHeaderViewDelegate {
    func headerView(headerView : XS_CouponHeaderView, didClickConvertBtn: UIButton)
}

class XS_CouponHeaderView: UICollectionReusableView {
    
    var delegate : XS_CouponHeaderViewDelegate?

    @IBOutlet weak var textField: QMUITextField!
    @IBOutlet weak var convertBtn: UIButton!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        textField.addTarget(self, action: #selector(textFieldDidChange(textField:)), for: .editingChanged)
    }
    
    @objc func textFieldDidChange(textField : QMUITextField){
        convertBtn.isEnabled = textField.text?.count ?? 0 > 0
    }
    
    @IBAction func convertBtnAction(_ sender: UIButton) {
        textField.resignFirstResponder()
        self.endEditing(true)
        if delegate != nil {
            delegate?.headerView(headerView: self, didClickConvertBtn: sender)
        }
    }
    
}
